package action;

import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author corneliugosa
 */
public class LogoutAction extends ActionSupport implements ServletRequestAware{

    private HttpServletRequest request;
    private String errorMessage;
  
    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }
    
    public String doLogout(){
        HttpSession session = request.getSession();
        
        if(session==null || session.getAttribute("logged")==null){
            return "failure";
        }else if(session.getAttribute("logged").equals("yes")){
            return SUCCESS;
        }
        
        errorMessage = "Error occured while logging out!";
        return "failure";
    }
    
     public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    
}
